﻿public class Solution {
    public int FindMaxForm(string[] strs, int m, int n)
    {
        int[,] dp = new int[m + 1, n + 1];

        foreach (string str in strs)
        {
            int zeroNum = 0;
            int oneNum = 0;
            for (int i = 0; i < str.Length; i++)
            {
                switch (str[i])
                {
                    case '0':
                        zeroNum++;
                        break;
                    case '1':
                        oneNum++;
                        break;
                }
            }

            for (int i = m; i >= zeroNum; i--)
            {
                for (int j = n; j >= oneNum; j--)
                {
                    dp[i, j] = Math.Max(dp[i, j], dp[i - zeroNum, j - oneNum] + 1);
                }
            }
        }
        return dp[m, n];
    }

    public static void Main(string[] args)
    {
        string[] strs = ["10", "0001", "111001", "1", "0"];
        int m = 5, n = 3;
        Solution solution = new Solution();
        int res = solution.FindMaxForm(strs, m, n);
        Console.WriteLine(res);
    }
}